package com.yegs.jindie.quartz;

import com.yegs.jindie.JindieApplication;
import com.yegs.jindie.entity.DeliveryTO;
import com.yegs.jindie.service.DeliveryService;
import com.yegs.jindie.util.ExcelUtil;
import com.yegs.jindie.util.TxtUtil;
import org.quartz.DisallowConcurrentExecution;

import java.io.File;
import java.io.FileInputStream;
import java.util.Date;
import java.util.List;


@DisallowConcurrentExecution
public class DeliveryJob extends BaseJob {

    private DeliveryService deliveryService = (DeliveryService) JindieApplication.applicationContext.getBean("deliveryService");

    @Override
    public String handle(Date beginDate, Date endDate, Integer int_last){
        try {
            String fileName = deliveryService.getFileName(endDate, int_last);
            List<DeliveryTO> list = deliveryService.getDelivery(beginDate, endDate);
            ExcelUtil.exporExcelByFtp(fileName, DeliveryTO.class, list);
            String path = TxtUtil.exporDeliveryTOTxt(fileName,list);
            FileInputStream fi = new FileInputStream(path);
            //super.upload(fi,path);
            return "执行成功";
        }catch (Exception e){
            e.printStackTrace();
            return e.getMessage();
        }
    }

}
